package imvu.rbox.struct.boxes
{
	import flash.geom.Point;
	
	public class BoxStruct extends Object
	{
		protected var nowID:Number;		//	当前的状态序号		
		
		protected var baseArray:Array;
		protected var cArray1:Array;
		protected var cArray2:Array;
		protected var cArray3:Array;
		
		public function BoxStruct()
		{
			baseArray = new Array();
			cArray1 = new Array();
			cArray2 = new Array();
			cArray3 = new Array();
			
			nowID = 0;
		}
		
		//	设置/读取对象的状态标识号 
		public function set id(num:Number):void
		{
			num = Math.floor(num);
			
			this.nowID = (num < 0) ? (4 - (num%4)) % 4 : (num > 3) ? num % 4 : num;
			
			// trace("设置ID完毕,取到数据::\n" + this.statue);
		}
		
		//	读取当前对象方向
		public function get id():Number
		{
			return this.nowID;
		}
		
		//	读取当前对象方向对应的数组序列标识
		public function get statue():Array
		{
			// trace("当前对象:" + this);
			// trace("取得当前状态:" + nowID);
			
			switch(nowID)
			{
				case 1 :
					return this.cArray1;
				
				case 2 :
					return this.cArray2;
				
				case 3 :
					return this.cArray3;
			}
			
			return this.baseArray; 
		}
		
		//	将对象转换成为一个数组
		public function toArray(num:Number = -1):Array
		{
			if(num >= 0)
			{
				this.id = num;
			}
			
			var tArray:Array = new Array();
			var dbArray:Array = this.statue;
			
			for(var i:int = 0; i < 4; i++)
			{
				tArray[i] = new Array();
				for(var j:int = 0; j < 4; j++)
				{
					tArray[i][j] = 0;
				}
			}
			
			// trace("nowArrow::" + this.nowID);			
			// trace("getFlag::" + dbArray);
			
			try
			{
				for(var m:int = 0; m < dbArray.length; m++)
				{
					var p:Point = dbArray[m];
					tArray[p.y][p.x] = 1;
				}
			}
			catch(e:*)
			{
				trace("SetDataError:: " + e);
			}
			
			return tArray;
		}		
	}
}